package com.softstao.guoyu.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.softstao.guoyu.R;
import com.softstao.guoyu.model.me.Apply;
import com.softstao.guoyu.ui.baseAdapter.RecycleViewBaseAdapter;
import com.softstao.guoyu.ui.baseAdapter.RecycleViewHolder;
import com.softstao.softstaolibrary.library.utils.LZUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by vaikus on 2017/7/4.
 */

public class RechargeApplyAdapter extends RecycleViewBaseAdapter<Apply> {
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private AdapterItemListener adapterItemListener;

    public RechargeApplyAdapter(List<Apply> datas) {
        super(datas, R.layout.layout_recharge_apply_list_item);
    }

    @Override
    public void convert(RecycleViewHolder holder, Apply apply) {
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        holder.itemView.setLayoutParams(layoutParams);
        String status = null;
        switch (apply.getState()){
            case 0:
                status = "待充值";
                holder.getView(R.id.btn).setVisibility(View.VISIBLE);
                holder.getView(R.id.reason).setVisibility(View.GONE);
                break;
            case 1:
                status = "已充值";
                holder.getView(R.id.btn).setVisibility(View.GONE);
                holder.getView(R.id.reason).setVisibility(View.GONE);
                break;
            case 2:
                status = "已取消";
                holder.getView(R.id.btn).setVisibility(View.GONE);
                holder.getView(R.id.reason).setVisibility(View.VISIBLE);
                break;
        }
        holder.setText(R.id.money,"+" + LZUtils.priceFormat(apply.getMoney()) + "元")
                .setText(R.id.status,status)
                .setText(R.id.time,format.format(new Date(apply.getDate())))
                .setText(R.id.reason,"取消原因："+apply.getReason());
        holder.getView(R.id.urge).setOnClickListener(v -> {
            if (adapterItemListener!=null){
                adapterItemListener.urge(holder.getAdapterPosition());
            }
        });
        holder.getView(R.id.cancel).setOnClickListener(v -> {
            if (adapterItemListener!=null){
                adapterItemListener.cancel(holder.getAdapterPosition());
            }
        });
    }

    public interface AdapterItemListener{
        void urge(int position);
        void cancel(int position);
    }

    public AdapterItemListener getAdapterItemListener() {
        return adapterItemListener;
    }

    public void setAdapterItemListener(AdapterItemListener adapterItemListener) {
        this.adapterItemListener = adapterItemListener;
    }
}
